package com.jk.myimkit.imkit;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.ViewFlipper;

import com.jk.myimkit.R;
import com.jk.myimkit.imkit.utilities.LangUtils;
import com.jk.myimkit.imkit.utilities.PermissionCheckUtil;

public class RongBaseActivity extends Activity {
    private ViewFlipper mContentView;
    protected ViewGroup titleContainer;

    public RongBaseActivity() {
    }

    protected void attachBaseContext(Context newBase) {
        Context context = LangUtils.getConfigurationContext(newBase);
        super.attachBaseContext(context);
    }

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        super.setContentView(R.layout.rc_base_activity_layout);
        this.titleContainer = (ViewGroup)this.findViewById(R.id.rc_ac_ll_base_title);
        View back = this.findViewById(R.id.rc_action_bar_back);
        back.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                RongBaseActivity.this.finish();
            }
        });
        this.mContentView = (ViewFlipper)this.findViewById(R.id.rc_base_container);
    }

    public void setContentView(int resId) {
        View view = LayoutInflater.from(this).inflate(resId, (ViewGroup)null);
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(-1, -1, 1.0F);
        this.mContentView.addView(view, lp);
    }

    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        if (!PermissionCheckUtil.checkPermissions(this, permissions)) {
            PermissionCheckUtil.showRequestPermissionFailedAlter(this, PermissionCheckUtil.getNotGrantedPermissionMsg(this, permissions, grantResults));
        } else {
            super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        }

    }
}
